package cc.aliza.lib.mongo.core.decoder;

import cc.aliza.lib.mongo.core.annotations.*;
import org.bson.Document;

import java.lang.reflect.Field;

/**
 * 『给时光以生命·给岁月以文明』
 *
 * @author Zhang Jing (byrdkm17@gmail.com).
 */
public final class DecoderFactory {

    public static Decoder create(Document document, Field field) {
        if (field.getAnnotation(Id.class) != null) {
            return new IdDecoder(document, field);
        }
        if (field.getAnnotation(Embed.class) != null) {
            return new EmbedDecoder(document, field);
        }
        if (field.getAnnotation(EmbedList.class) != null) {
            return new EmbedListDecoder(document, field);
        }
        if (field.getAnnotation(Ref.class) != null) {
            return new RefDecoder(document, field);
        }
        if (field.getAnnotation(RefList.class) != null) {
            return new RefListDecoder(document, field);
        }
        if (field.getAnnotation(Ignore.class) != null) {
            return null;
        }
        return new PropertyDecoder(document, field);
    }
}
